from pynput import keyboard

from layouts import cmd
from actions import action
from config import rcmap

import os

def on_press(key):
    os.system('clear')
    match key:
        case cmd.roll_up:
            action.pwm_change(rcmap.roll.value, True)
            print("ROLL+")
        case cmd.roll_down:
            action.pwm_change(rcmap.roll.value, False)
            print("ROLL-")
        case cmd.pitch_up:
            action.pwm_change(rcmap.pitch.value, True)
            print("PITCH+")
        case cmd.pitch_down:
            action.pwm_change(rcmap.pitch.value, False)
            print("PITCH-")
        case cmd.throttle_up:
            action.pwm_change(rcmap.throttle.value, True)
            print("THR+")
        case cmd.throttle_down:
            action.pwm_change(rcmap.throttle.value, False)
            print("THR-")
        case cmd.yaw_up:
            action.pwm_change(rcmap.yaw.value, True)
            print("YAW+")
        case cmd.yaw_down:
            action.pwm_change(rcmap.yaw.value, False)
            print("YAW-")

        case cmd.arm:
            action.arm()
            print("ARM")
        case cmd.disarm:
            action.disarm()
            print("DISARM")
        
        case cmd.stabilize:
            action.stabilize()
            print("STAB")
        case cmd.alt_hold:
            action.alt_hold()
            print("A_H")
        
        case cmd.reset:
            action.reset()
            print("RESET")

        case cmd.terminate:
            exit(0)

def on_release(key):
    print('')


keyboard_listener = keyboard.Listener(
   on_press=on_press,
   on_release=on_release
)
keyboard_listener.start()


keyboard_listener.stop()
